﻿// DotConference
// Copyright (c) 2009 Jean-François Blais <zerathulous@hotmail.com>
// Copyright (c) 2009 Thomas Gagnon <gagnonthomas@gmail.com>
// Copyright (c) 2009 André Lalancette <andlal@hotmail.com>
// Copyright (c) 2009 Michaël Larouche <larouche@kde.org>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using DotConferenceCore.Logistique;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

namespace TestDotConferenceCore
{
    [TestFixture]
    public class TestSessionParallele
    {
        private SessionParallele sessionParallele;
        private Local local1;
        private Local local2;
        private Local local3;

        [SetUp]
        public void Init()
        {
            sessionParallele = new SessionParallele(new DateTime(2009, 10, 2, 10, 0, 0),
                                                    new DateTime(2009, 10, 2, 12, 0, 0));
            local1 = new Local()
            {
                Numero = "P0-5000",
                Capacite = 400
            };

            local2 = new Local()
            {
                Numero = "P1-7010",
                Capacite = 80
            };

            local3 = new Local()
            {
                Numero = "P2-1030",
                Capacite = 150
            };
        }

        [Test]
        public void SessionParalleleNormale()
        {
            var session1 = new Session(new DateTime(2009, 10, 2, 10, 0, 0), new DateTime(2009, 10, 2, 12, 0, 0))
            {
                Titre = "AI",
                Local = local1
            };

            var session2 = new Session(new DateTime(2009, 10, 2, 10, 0, 0), new DateTime(2009, 10, 2, 11, 30, 0))
            {
                Titre = "Langage de prog",
                Local = local2
            };

            var session3 = new Session(new DateTime(2009, 10, 02, 11, 00, 00), new DateTime(2009, 10, 02, 12, 00, 00))
            {
                Titre = "Game Design",
                Local = local3
            };

            sessionParallele.AjouterSession(session1);
            sessionParallele.AjouterSession(session2);
            sessionParallele.AjouterSession(session3);

            Assert.That(sessionParallele.Sessions.Count, Is.EqualTo(3));
        }

        [Test]
        [ExpectedException(typeof(SessionParalleleHorsPlageException))]
        public void AjoutSessionHorsPlage()
        {
            var session1 = new Session(new DateTime(2009, 10, 2, 13, 0, 0), new DateTime(2009, 10, 2, 16, 0, 0))
            {
                Titre = "AI",
                Local = local1
            };

            sessionParallele.AjouterSession(session1);
        }

        [Test]
        [ExpectedException(typeof(SessionParalleleHorsPlageException))]
        public void AjoutSessionQuiDepasse()
        {
            var session1 = new Session(new DateTime(2009, 10, 2, 10, 0, 0), new DateTime(2009, 10, 2, 16, 0, 0))
            {
                Titre = "AI",
                Local = local1
            };

            sessionParallele.AjouterSession(session1);
        }

        [Test]
        [ExpectedException(typeof(SessionParalleleLocalConflitException))]
        public void AjoutSessionMemeLocal()
        {
            var session1 = new Session(new DateTime(2009, 10, 2, 10, 0, 0), new DateTime(2009, 10, 2, 12, 0, 0))
            {
                Titre = "AI",
                Local = local1
            };

            var session2 = new Session(new DateTime(2009, 10, 2, 10, 0, 0), new DateTime(2009, 10, 2, 11, 30, 0))
            {
                Titre = "Langage de prog",
                Local = local1
            };

            sessionParallele.AjouterSession(session1);
            sessionParallele.AjouterSession(session2);
        }

        [Test]
        [ExpectedException(typeof(SessionParalleleMemeTitreException))]
        public void AjoutSessionMemeTitre()
        {
            var session1 = new Session(new DateTime(2009, 10, 2, 10, 0, 0), new DateTime(2009, 10, 2, 12, 0, 0))
            {
                Titre = "AI",
                Local = local1
            };

            var session2 = new Session(new DateTime(2009, 10, 2, 10, 0, 0), new DateTime(2009, 10, 2, 11, 30, 0))
            {
                Titre = "AI",
                Local = local2
            };

            sessionParallele.AjouterSession(session1);
            sessionParallele.AjouterSession(session2);
        }
    }
}